1. Field of the Invention
The present invention relates to a compiler that translates a source program into an object program and an optimization method by the compiler, and more particularly, to a compiler capable of reducing interrupt handling and its optimization method.
2. Description of the Related Art
It is necessary for a compiler which is intended for a device having an interrupt handling function in its architecture to deal with the above interrupt handling function at the compile time. Generally, a routine branching at the occurrence of interruption in a device, that is, an interruption function is designed to be described in a source program, thereby making it possible to deal with the above interrupt handling function.
The interruption function branches irregularly during the execution of a source program. In order to protect the content of a register which has been used before branching, all the contents of the registers that may be used must be saved at the start of the interruption function, and the contents of the saved registers must be returned after finishing the interruption function.
As this kind of the conventional technique, there is an apparatus disclosed in Japanese Patent Publication Laid Open (Kokai) No. Heisei 2-257224, "Linkage Edit Processor". A linkage edit processor disclosed in the same publication deletes a redundant instruction for instructing the saving/return of a register when a register used at a function calling party (calling register) and a register used at a function called party (called register) are not in accord with each other, on the condition that there is no recursive call. Thus, edit processing to reduce the code size and shorten the execution time of a source program is optimized.
This optimization method of edit processing, in the normal function call, requires a code for providing a saving instruction of a calling register before a function call instruction and providing a return instruction of the saved register after the function call instruction, in order not to destroy the content of the calling register at the called party. Provided with a table for registering the call function information and the using register information, this method deletes unnecessary saving/return codes of a register which is not used at the called party, of the saved/returned registers of the function at the calling party, referring to the above table.
FIG. 7 shows a constitutional example of the conventional compiler which deletes the saving/return codes of an unnecessary register in the same way as the optimization method of edit processing disclosed in the Patent Publication No. 2-257224. The compiler shown in FIG. 7 comprises an input unit 701 for receiving a source program to perform a lexical analysis, a syntax analysis unit 702 for generating a syntactic tree after analysis of the syntax from a lexical array, an optimization unit 703 for optimizing the syntax tree, a code generation unit 704 for generating an intermediate code 712 based on the optimized syntax tree, a using register control table by function 705 for registering information on a call function and a using register, a using register extracting unit by function 706 for registering a call function name and a using register in every function into the using register control table by function 705 after analysis of the intermediate code 712, and an output unit 708 for supplying an assembly program file 713 having the saving/return codes of a register which is not used at the called party deleted therefrom.
By reference to FIG. 7, it will be easily understood that the conventional compiler optimization method disclosed in the Patent Publication No. 2-257224 can be realized, in a compiler, by additionally providing the output unit 708 for deleting the saving/return code of a register which is not used at the called party, of the saved/returned registers of the function at the calling party, referring to the using register control table by function 705 and the using register extracting unit by function 706 which supplies the information to the same table, after the code generation unit 704 of a general compiler.
This time, the conventional optimization method of a compiler will be described with reference to FIG. 7 and FIG. 6 showing an example of the source program 711. With reference to the portion corresponding to the intermediate code 712 supplied by the code generation unit 704, in the source program shown in FIG. 6, there is a saving code of the registers "g", "h" used by the function f6, before a call function for the function f5 existing within the function f6, and there is a return code of the registers "g", "h" used by the function f6, after the call function for the function f5.
According to the input intermediate code 712, the using register extracting unit by function 706 recognizes the definition of the function f6 and registers the function name f5 called from the function f6 and the register names "g", "h" used by the function f6 into the using register control table by function 705. Next, it recognizes the definition of the function f5 and registers the register name "f" used by the function f5 into the using register control table by function 705.
The output unit 708 recognizes that no overlapped register name is found between the registers "g", "h" used by the function f6 and the register "f" used by the function f5, with reference to the using register control table by function 705. Then, a saving code of the registers "g", "h" before the call instruction for the function f5 and a return code of the registers "g", "h" after the call instruction for the function f5 are deleted, thereby to supply the assembly program file 713.
The above-mentioned conventional optimization method of a compiler, however, cannot delete the saving/return codes of a register as for a function branching from certain address of a program, like an interruption function.
This is why an interruption function having no function at the calling party will not destroy the content of a register in use at the occurrence time of an interruption of a device; although it is necessary to provide a saving instruction of a register at the head of the interruption function corresponding to a function called party and provide its return instruction at the end of the interruption function, the using register information of a function at the calling party is required in order to delete these saving/return codes; therefore, unnecessarily saved/returned register cannot be detected.
Referring to FIGS. 6 and 7 again, since the function f6 is an interruption function, saving of a register and return of a register are performed respectively at the head and at the end of the function f6 and a register in use at the occurrence time of an irregular interruption is not clear. Therefore, all the registers are saved at the head of the function f6 and all the registers are returned at the end thereof.
The conventional output unit 708 deletes the saving/return codes of a register not in use at the called party, from the saving/return codes of the calling register, in the using register control table by function 705. Therefore, the saving code of all the registers at the head of the function f6 and the return code of all the registers at the end of the function f6 cannot be deleted.
As mentioned above, the conventional compiler and the conventional optimization method thereof is defective in that the saving/return codes of a register cannot be deleted in a function branching at certain address of a program, like an interruption function.